package org.i1510.common.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.i1510.common.bean.PageBean;
import org.i1510.common.dao.ISysRolePopDao;
import org.i1510.common.po.SysRolePop;
import org.i1510.common.service.ISysRolePopService;
import org.i1510.common.utils.BeanUtils;
import org.i1510.common.utils.web.ResultMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service("iSysRolePopService")
public class SysRolePopServiceImpl extends BaseServiceImpl implements
		ISysRolePopService {
	@Autowired
	private ISysRolePopDao iSysRolePopDao;

	@Transactional
	public ResultMapper saveAll(List<SysRolePop> list) {

		ResultMapper mapper = ResultMapper.generateFailure();

		List<SysRolePop> listSaved = iSysRolePopDao.save(list);
		
		if (listSaved == null) {
			return null;
		}
		mapper = ResultMapper.generateSuccess();
		mapper.appendResult("baseRtn", listSaved);
		return mapper;
	}

	public ResultMapper save(SysRolePop basePo) {

		ResultMapper mapper = ResultMapper.generateFailure();
		SysRolePop saved = iSysRolePopDao.save(basePo);
		if (saved == null) {
			return null;
		}	
		mapper = ResultMapper.generateSuccess();
		mapper.appendResult("baseRtn", saved);
		return mapper;
	}
	public ResultMapper delete(String fdId) {

		ResultMapper mapper = ResultMapper.generateFailure();
		iSysRolePopDao.delete(fdId);
		mapper = ResultMapper.generateSuccess();
		return mapper;
	}
	
	public SysRolePop findById(String fdId){
		SysRolePop  SysRolePop = iSysRolePopDao.findById(fdId);
		return SysRolePop;
	}
	public List<SysRolePop> findByIds(List<String> fdIds){
		return (List<SysRolePop>) iSysRolePopDao.findAll(fdIds);
	}
	public List getPage(SysRolePop sysRolePop, PageBean pageBean,Map conditions) {
		Map map = new HashMap();
		// Bean转成Map
		BeanUtils.ObjectCopyMap(sysRolePop, map);
		map.put("intPageIndex", pageBean.getIntPageIndex());
		map.put("intPageSize", pageBean.getIntPageSize());
		map.putAll(conditions);
		List list = this.queryForListBySql("sysRolePopSql.getPage", map);
		return list;
	}

	public int getPageCount(SysRolePop sysRolePop,Map conditions) {
		Map map = new HashMap();
		// Bean转成Map
		BeanUtils.ObjectCopyMap(sysRolePop, map);
		map.putAll(conditions);
		List list = this.queryForListBySql("sysRolePopSql.getPageCount", map);
		return list.size();
	}

}
